package com.kly.user.serviceImpl;

import cn.hutool.core.bean.BeanUtil;
import com.fqgj.common.api.Response;
import com.kly.user.db.dao.SwitchManageDao;
import com.kly.user.db.entity.SwitchManageEntity;
import com.kly.user.dto.SwitchManageDto;
import com.kly.user.service.UserSwitchManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @ClassName: UserSwitchManageServiceImpl
 * @description: 用户开关设置
 * @author: yuwn
 * @create: 2023-11-30 11:43
 */
@Service("userSwitchManageService")
public class UserSwitchManageServiceImpl implements UserSwitchManageService {

    @Autowired
    private SwitchManageDao switchManageDao;

    @Override
    public Response<List<SwitchManageDto>> getSwitchManageList(String packageName, Integer switchType, String appVersionName, Integer appVersion) {

        Map<String, Object> params = new HashMap<>();
        params.put("deleted", 0);
        params.put("packageName", packageName);
        params.put("appVersionName", appVersionName);
        params.put("appVersion", appVersion);
        params.put("switchType",switchType);
        List<SwitchManageEntity> list = switchManageDao.selectByParams(params);

        return Response.ok(list.parallelStream().map(x->{
            SwitchManageDto switchManageDto = new SwitchManageDto();
            BeanUtil.copyProperties(x,switchManageDto);
            return switchManageDto;
        }).collect(Collectors.toList()));
    }
}
